package com.yc.http.v1.impl;

import com.yc.http.v1.HttpServletImpl;
import com.yc.http.v1.HttpServletRequest;
import com.yc.http.v1.HttpServletResponse;
import com.yc.http.v1.ServletException;

import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.net.URLDecoder;

@WebServlet("/hello.s")
public class HelloWorldServlet extends HttpServletImpl {

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        response.setContentType("text/html;charset=utf-8");
        // URLDecoder.decode(name, "UTF-8");
        String name = request.getParameter("name");
        if(name == null){
            name = "world";
        }
        response.getWriter().append("<h1>hello " + name + "</h1>");
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        doGet(request, response);
    }

    @Override
    public void doOptions(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        doGet(request, response);
    }
}
